<?

	$postUrl = $this->getConfirmUrl();
	//$shopUrl = $this->getShopUrl();

	$shopUrl = "/Donations-Bequests/";
	$cartUrl = $this->getCartUrl();

 	$currency = $this->getCurrency();
 	$currencySign = $this->getCurrencySign();

 	//if we have only one order
 	if (1 < count($this->orderContainer->orderItems()) ){
 		$removeItemReturnUrl= $this->getCartUrl();
 	} else {
 		$removeItemReturnUrl = $this->getShopUrl();
 	}

 	$ik = $this->orderContainer->valueForKey('invalidKeys');

 	global $_POST;
 	//echo "post = <pre>";print_r($_POST);echo "</pre><br />";

 	$formData = array();

 	//global $_SESSION;
 	if(isset($_POST['formMailerDataForOrderItem'])){
 		$formData = unserialize($_POST['formMailerDataForOrderItem']);
	} else {

		//loop through order items and pull out form data if it is set
		foreach ($this->orderContainer->orderItems() as $oi) {
			if(strlen($oi->valueForKey('formMailerDataForOrderItem')) > 0){
				$formData = unserialize($oi->valueForKey('formMailerDataForOrderItem'));
			}
		}

	}

 	//echo "session = <pre>";print_r($_SESSION);echo "</pre><br />";
 	//echo "formDataForCart = <pre>";print_r($formDataForCart);echo "</pre><br />";



 	/*if(isset($formDataForCart)){
 		foreach($formDataForCart as $formType){
 			//echo "Form Type = <pre>";print_r($formType); echo "</pre><br />";
 			foreach($formType as $formDataItem){
 				//echo "Form Item = <pre>";print_r($formDataItem);echo "</pre><br />";
 				$formData = $formDataItem;
 			}
 		}
 	}*/
 	//echo "form Data = <pre>";print_r($formData);echo "</pre></br />";

 	$firstname = extractStringWithKeyFromArray('firstName', $formData, '');
 	$lastname = extractStringWithKeyFromArray('lastName', $formData, '');
 	$email = extractStringWithKeyFromArray('email', $formData, '');
 	$emailConfirm = extractStringWithKeyFromArray('email', $formData, '');
 	$phone = extractStringWithKeyFromArray('phone', $formData, '');
 	$street = extractStringWithKeyFromArray('street', $formData, '');
 	$suburb = extractStringWithKeyFromArray('suburb', $formData, '');
 	$city = extractStringWithKeyFromArray('city', $formData, '');

?>
<table align="center" cellpadding="0" cellspacing="0" id="purchaseDetails" >
  <tr>
    <td valign="middle" class="tableCell item"><strong>Item</strong></td>
    <td align="right" valign="middle" class="tableCell cartprice"><strong>Price </strong></td>
    <td align="right" valign="middle" class="tableCell qty"><strong>Qty</strong></td>
    <td align="right" valign="middle" class="tableCell subtotal"><strong>Sub-total</strong></td>
    <td align="right" valign="middle" class="tableCellR remove">&nbsp;</td>
  </tr>
<?


	foreach ($this->orderContainer->orderItems() as $oi) {


	//	if(isset($this->orderContainer) && !is_null($this->orderContainer)){
			 //$orderItems = $this->orderContainer->orderItems();

			 //foreach($orderItems as $orderItem){
				//myPrintR($oi);
				$pid = $oi->valueForKey('productId');
				$oid = $oi->valueForKey('id');
				$subTotal = $oi->valueForKey('subTotal');
				$quantity = $oi->valueForKey('quantity');
				$price = $oi->valueForKey('price');

				//$imgSrc = "/html/blob.php?documentCode=" . $pid . "&amp;elementId=11142";
			 	// we need to get the currency and the price and what not..
			 	$imgSrc = $oi->valueForKey("productInvoiceImageUrl");
			 	$itemUrl = $oi->valueForKey("productUrl");
			 	$product = $oi->getProduct();
			 	$itemDescription = $oi->valueForKey("productInvoiceDescription");
			 	if($product->documenttypecode == 'docArtwork'){
			 		$shopUrl = '/Artworks-For-Sale/';
			 	} elseif($product->documenttypecode == 'docMember'){
			 		$shopUrl = "/Membership/";
			 	} elseif($product->documenttypecode == 'docClasses') {
			 		$shopUrl = '/Classes/';
			 	} elseif($product->documenttypecode == 'docExhibit') {
			 		$shopUrl = '/Exhibitions/Entry-Forms/';
			 	}
?>
  <tr>
    <td valign="middle" class="tableCell item"><a href="<?= $itemUrl ?>" ><img src="<?= $imgSrc; ?>" class="cartImg" alt=""/></a> <a href="<?= $itemUrl ?>" class="cartItemTitle" ><?= $product->title ?></a><?php echo $itemDescription; ?></td>
    <td align="right" valign="middle" class="tableCell cartprice">  <?= $currencySign ?><? printf("%01.2f",  $price);?><?= " " . $currency ?> </td>
    <td align="right" valign="middle" class="tableCell qty"><?= $quantity ?></td>
    <td align="right" valign="middle" class="tableCell subtotal"><span class="subTotal"><?= $currencySign ?><? printf("%01.2f",  $subTotal );?> <?= " " . $currency ?> </span></td>
    <td align="right" valign="middle" class="tableCellR remove"><a title="Remove From Order" href="/Cart/?deleteItemFromContainer=<?= $oid; ?>&amp;returnUrl=<?=urlencode($removeItemReturnUrl)?>" ><img src="/images/cartRemove.gif" alt="Remove item" /></a></td>
  </tr>
<?

	}



		//nothing for shipping???
		//free on this site..
?>

  <tr>
  		<td colspan="3" align="right" class="tableCell shippingFee">Shipping Fee
  		</td>
	  <td align="right" class="tableCell">
	     <div id="cartShipping"><?php
	      if($this->orderContainer->valueForKey("shippingPrice") == "TBA"){
	      	echo $this->orderContainer->valueForKey("shippingPrice");
	      } else {
		      echo $currencySign;
		      printf("%01.2f",  $this->orderContainer->valueForKey('shippingPrice'));
		      echo  " " . $currency;
	      }

	       ?></div></td>
	  </td>
	  <td class="tableCellR">&nbsp;
	  </td>
  </tr>

  <tr>
    	<td colspan="3" align="right" class="tableCell total">Total
  		</td>
	  <td align="right" class="tableCell">
	     <div id="cartTotal"><?= $currencySign ?><? printf("%01.2f",  $this->orderContainer->valueForKey('totalPrice'));?> <?= " " . $currency ?></div></td>
	  </td>
	  <td class="tableCellR">&nbsp;
	  </td>
  </tr>

  <tr>
    <td colspan="5" valign="middle" class="tableCellBR" align="right">

    <div id="cartControl"> <?php // /* ?><a href="/Cart/?orderStep=cancelOrder"><img src="/images/cartClear.gif" alt="Clear your entire order" /></a>&nbsp;&nbsp;<?php // */ ?><a href="<?= $shopUrl ?>"><img src="/images/cartContinue.gif" alt="Continue looking" /></a> </div>
    </td>
  </tr>

</table>










<div class="divider"></div>







 <form id="cartForm" name="cartForm" method="post" action="<?= $postUrl ?>" enctype="multipart/form-data">

			  <table cellpadding="0" cellspacing="0" id="shippingDetails" >
                      <tr>
                        <td colspan="2" align="left" valign="top"><h4>Your Details:</h4></td>

                      </tr>
						<?
								if (!$this->orderContainer->isKeyValid('termsAgree')){
						?>
							       <tr><td>&nbsp;</td><td>&nbsp;<span class="orderValidationError" > You must accept the terms and conditions.</span></td></tr>
						<?
						 		}
						?>
                      <tr>
                        <td width="155" align="right" valign="middle" class="tableCell" >First Name:<span class="asterix">*</span> </td>
                        <td width="196" valign="middle" class="tableCellR"><input type="text" name="<?= $this->orderContainer->keyForField('firstName') ?>" id="firstName" value="<?php if(strlen($this->orderContainer->valueForKey('firstName')) > 0){ echo $this->orderContainer->valueForKey('firstName');} elseif(strlen($firstname) > 0) { echo $firstname;} ?>"  size="60" maxlength="100" />
<?
		if (!$this->orderContainer->isKeyValid('firstName')){
?>
	      <br /><span class="orderValidationError" > First Name is a Required Field.</span>
<?
		}
?>

                        </td>
                      </tr>
                      <tr>
                        <td align="right" valign="middle" class="tableCell" >Last Name:<span class="asterix">*</span> </td>

                        <td valign="middle" class="tableCellR"><input type="text" name="<?= $this->orderContainer->keyForField('lastName') ?>" id="lastName" value="<?php if(strlen($this->orderContainer->valueForKey('lastName')) > 0){ echo $this->orderContainer->valueForKey('lastName');} elseif(strlen($lastname) > 0) { echo $lastname;} ?>"  size="60" maxlength="100" />
<?
		if (!$this->orderContainer->isKeyValid('lastName')){
?>
	      <br /><span class="orderValidationError" > Last Name is a Required Field.</span>
<?
		}
?>

                        </td>
                      </tr>
                      <tr>
                        <td align="right" valign="middle" class="tableCell" >Email:<span class="asterix">*</span> </td>
                        <td valign="middle" class="tableCellR"><input type="text" name="<?= $this->orderContainer->keyForField('email') ?>" id="email" value="<?php if(strlen($this->orderContainer->valueForKey('email')) > 0){ echo $this->orderContainer->valueForKey('email');} elseif(strlen($email) > 0) { echo $email;} ?>"  size="60" maxlength="100" />
<?
		if (!$this->orderContainer->isKeyValid('email')){


?>
	      <br /><span class="orderValidationError" >Email Address <?= $ik['email'] ?>.</span>
<?
		}
?>

                        </td>
                      </tr>

                      <tr>
                        <td align="right" valign="middle" class="tableCell">Verify Email:<span class="asterix">*</span> </td>
                        <td valign="middle" class="tableCellR"><input type="text" name="<?= $this->orderContainer->keyForField('verifyEmail') ?>" id="verifyEmail" value="<?php if(strlen($this->orderContainer->valueForKey('verifyEmail')) > 0){ echo $this->orderContainer->valueForKey('verifyEmail');} elseif(strlen($email) > 0) { echo $email;} ?>" size="60" maxlength="100" />
<?
 		if (!$this->orderContainer->isKeyValid('verifyEmail')){

?>
	      <br /><span class="orderValidationError" > Verify Email Address <?= $ik['verifyEmail'] ?>.</span>
<?
 		}
?>

                        </td>
                      </tr>
                      <tr>
                        <td align="right" valign="middle" class="tableCell">Ph:()<span class="asterix">*</span><br />                        </td>

                        <td valign="middle" class="tableCellR"><input type="text" name="<?= $this->orderContainer->keyForField('phone') ?>" id="phone" value="<?php if(strlen($this->orderContainer->valueForKey('phone')) > 0){ echo $this->orderContainer->valueForKey('phone');} elseif(strlen($phone) > 0) { echo $phone;} ?>" size="60" maxlength="100" />
<?
		if (!$this->orderContainer->isKeyValid('phone')){
?>
	      <br /><span class="orderValidationError" > Phone is a Required Field.</span>
<?
		}
?>

                        </td>
                      </tr>
                      <?php /* ?>
					  <tr>
					    <td align="right" valign="middle" class="tableCell"><strong>Where did you hear about us?</strong></td>
					    <td valign="middle" class="tableCellR">

<?
	$hearAboutUsKey = $this->orderContainer->keyForField('hearAboutUs');
?>
					    	<select name="<?= $hearAboutUsKey ?>" id="hearAboutUs">
						    	<option></option>
<?
	$hearAboutUsOptions = array("Search Engine","Magazine","Friend","Store","Other");
	foreach ($hearAboutUsOptions as $hearAboutUsOption){
?>
<option <?= ($this->orderContainer->valueForKey('hearAboutUs') == $hearAboutUsOption ) ? "selected=\"selected\"" : "" ?> ><?= $hearAboutUsOption ?></option>
<?
	}
?>
					    	</select>



						    </td>
				      </tr>
				      <?php */ ?>

	    </table>




				<table cellpadding="0" cellspacing="0" id="shippingAddress">
					  <tr valign="top">
						<td colspan="2"><h4>Delivery Address:</h4></td>
					  </tr>
					  <tr>
						<td align="right" valign="middle" class="tableCell" >Address Line 1:<span class="asterix">*</span> </td>
						<td valign="middle" class="tableCellR"><input type="text" name="<?= $this->orderContainer->keyForField('street') ?>" id="street" value="<?php if(strlen($this->orderContainer->valueForKey('street')) > 0){ echo $this->orderContainer->valueForKey('street');} elseif(strlen($street) > 0) { echo $street;} ?>" size="60" maxlength="100" />
<?
		if (!$this->orderContainer->isKeyValid('street')){
?>
	      <br /><span class="orderValidationError" > Street is a Required Field.</span>
<?
		}
?>
						</td>
					  </tr>
					  <tr>
						<td width="136" align="right" valign="middle" class="tableCell" >Address Line 2:<span class="asterix">*</span></td>
						<td valign="middle" class="tableCellR"><input type="text" name="<?= $this->orderContainer->keyForField('suburb') ?>" id="suburb" value="<?php if(strlen($this->orderContainer->valueForKey('suburb')) > 0){ echo $this->orderContainer->valueForKey('suburb');} elseif(strlen($suburb) > 0) { echo $suburb;} ?>" size="60" maxlength="100" />									<?
									if (!$this->orderContainer->isKeyValid('suburb')){
							?>
								      <br /><span class="orderValidationError" > Suburb is a Required Field.</span>
							<?
									}
							?>

						</td>
					  </tr>
					  <tr>
						<td align="right" valign="middle" class="tableCell" >City:<span class="asterix">*</span></td>
						<td width="202" valign="middle" class="tableCellR"><input type="text" name="<?= $this->orderContainer->keyForField('city') ?>" id="city" value="<?php if(strlen($this->orderContainer->valueForKey('city')) > 0){ echo $this->orderContainer->valueForKey('city');} elseif(strlen($city) > 0) { echo $city;} ?>" size="60" maxlength="100" />
<?
		if (!$this->orderContainer->isKeyValid('city')){
?>
	      <br /><span class="orderValidationError" > City is a Required Field.</span>
<?
 		}
?>
						</td>
					  </tr>
					  <tr>
						<td align="right" valign="middle" class="tableCell" >State /  Region:</td>
						<td width="202" valign="middle" class="tableCellR"><input type="text" name="<?= $this->orderContainer->keyForField('state') ?>" id="state" value="<?= $this->orderContainer->valueForKey('state') ?>" size="60" maxlength="100" />						</td>
					  </tr>
					  <tr>
						<td align="right" valign="middle" class="tableCell" >ZIP/Postal Code:<span class="asterix"></span></td>
						<td width="202" valign="middle" class="tableCellR">
						<input type="text" name="<?= $this->orderContainer->keyForField('zip') ?>" id="zip" value="<?= $this->orderContainer->valueForKey('zip') ?>" size="60" maxlength="100" />
<?
		if (!$this->orderContainer->isKeyValid('zip')){
?>
	      <br /><span class="orderValidationError" > ZIP/Postal Code is a Required Field.</span>
<?
 		}
?>

						</td>
					  </tr>

					  <tr>
					    <td align="right" valign="top" class="tableCell"><strong>Country:</strong><span class="asterix">*</span></td>
					    <td valign="top" class="tableCellR">
					      <? /* <select name="cd261d34_country" id="country"  onchange="document.forms['shippingForm'].submit();">
                            <option value="140"  selected="selected">New Zealand - North Island</option>
                            <option value="249" >New Zealand - South Island</option>
                          </select> */ ?>
<?php
		$countries = $this->orderContainer->valueForKey('countryList');
?>
					      <select name="<?= $this->orderContainer->keyForField('country') ?>" id="country" class="body">


<?
		//$countryTableWriter = new CmsTableWriter('country',$db);
		//$countryTableWriter->resetCustomIterator(" WHERE iso_3166_1_alpha_2 <> '' AND iso_3166_1_alpha_2 <> 'ZZ' ORDER BY name ASC ");
		//while (($row = $countryTableWriter->nextItem())){

		foreach($countries as $row){
			//clean those that could have cruft..
			$name = magicClean($row->name);
			$id = $row->id;
			//$countrycode = $row->iso_3166_1_alpha_2;
?>
                <option value="<?= $id ?>" <? if($id ==  $this->orderContainer->valueForKey('country') ) echo " selected=\"selected\""; ?>><?= $name ?></option>
<?
		}
?>
                  </select>
<?
		if (!$this->orderContainer->isKeyValid('country')){
?>
	      <br /><span class="orderValidationError"  > Country is a Required Field.</span>
<?
		}
?>	    </td>
			      </tr>

					  <tr>
						<td align="right" valign="top" class="tableCell"><strong>Comments:</strong><br /></td>
						<td valign="top" class="tableCellR"><textarea name="<?= $this->orderContainer->keyForField('comments') ?>" id="comments" cols="55" rows="7"><?= magicClean($this->orderContainer->valueForKey('comments')) ?></textarea>
						</td>
					  </tr>
				</table>

<div class="clear"></div>


					<div id="purchaseSubmit">

						<div id="submitArea">
						<div id="cartTermsAgree">
							Please check your order carefully before submitting.<br/><br/>
							<span class="asterix">*</span> I have read and agree to the <a href="/Terms-And-Conditions/" target="_blank">Terms &amp; Conditions</a> <input type="checkbox" name="<?= $this->orderContainer->keyForField('termsAgree') ?>" id="termsAgree" <? if ( $this->orderContainer->valueForKey('termsAgree')) { echo "checked=\"checked\"";} ?> value='true' /><br /> (You must accept the terms &amp; conditions)
<?
		if (!$this->orderContainer->isKeyValid('termsAgree')){
?>
	      <br /><span class="orderValidationError" > You must accept the terms and conditions.</span>
<?
 		}
?>
						</div>

						<input name="image" type="image" class="confirm" src="/images/cartConfirm.gif" alt="Confirm Order"  />
						<a id="showTerms" href="#Terms" rel="ibox"></a>

						</div>


					</div>



	  </form>




<div class="divider"></div>